#!/usr/bin/perl
#########################################################################################
#   HPCBench
#
#   File: uninstallBench
#   Description:  Skript to uninstall hpc-bench benchmark packages
#
#   Version:  1.0
#
#   Author:  Jan Treibig (jt), jan.treibig@gmail.com
#   Company:  RRZE Erlangen
#   Copyright:  Copyright (c) 2011, Jan Treibig
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License, v2, as
#   published by the Free Software Foundation
#  
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#  
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#########################################################################################

use strict;
use warnings;
use Cwd 'abs_path';
use File::Basename;

if (not defined  $ARGV[0]) {
    die "Usage: uninstallBench <Benchmark>\n";
}

my $BM_ROOT = abs_path('./');
my $BenchmarkName = $ARGV[0];

system("rm -rf $BM_ROOT/bench/$BenchmarkName");

# Patch benchset.mk
open INFILE,"< $BM_ROOT/benchset.mk";
open OUTFILE,"> $BM_ROOT/benchset_tmp.mk";

while (<INFILE>) {
    my $line = $_;

    if (not $line =~ /$BenchmarkName/) {
        print OUTFILE $line;
    }
}
    
close OUTFILE;
close INFILE;

system("mv -f  $BM_ROOT/benchset_tmp.mk  $BM_ROOT/benchset.mk");

